package com.neuedu.shop.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.shop.mapper.CollectMapper;
import com.neuedu.shop.pojo.Collect;
import com.neuedu.shop.service.CollectService;

@Service
@Transactional
public class CollectServiceImpl implements CollectService {
	
	@Autowired
	private CollectMapper mapper;
	@Override
	public void insert(Collect collect) {
		List<Collect> collects = findByUserid(collect.getUserid());
		for(int i=0;i<collects.size();i++) {
			Collect co = collects.get(i);
			if(co.getProduct().getId().equals(collect.getProductid())) {
				return;
			}
		}
		mapper.insert(collect);
	}

	@Override
	public List<Collect> findByUserid(Integer userid) {
		return mapper.findByUserid(userid);
	}

}